﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
///WebPath 的摘要说明
/// </summary>
public class WebPath
{
    public WebPath()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    /// <summary>
    /// 取得网站的根目录的URL
    /// </summary>
    /// <returns></returns>
    public static string GetRootURI()
    {
        string AppPath = "";

        HttpContext HttpCurrent = HttpContext.Current;
        HttpRequest Req;
        if (HttpCurrent != null)
        {
            Req = HttpCurrent.Request;

            string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
            if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                //直接安装在   Web   站点  
                AppPath = UrlAuthority;
            else
                //安装在虚拟子目录下  
                AppPath = UrlAuthority + Req.ApplicationPath;
        }
        return AppPath;
    }
    /// <summary>
    /// 取得网站的根目录的URL
    /// </summary>
    /// <param name="Req"></param>
    /// <returns></returns>
    public static string GetRootURI(HttpRequest Req)
    {
        string AppPath = "";
        if (Req != null)
        {
            string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
            if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                //直接安装在   Web   站点  
                AppPath = UrlAuthority;
            else
                //安装在虚拟子目录下  
                AppPath = UrlAuthority + Req.ApplicationPath;
        }
        return AppPath;
    }
}